<html>
<head>
	 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>一人一本 - 购物车</title>

    <!--<link href="css/bootstrap.css" rel="stylesheet">-->
	<!--<link href="css/bootstrap-responsive.min.css" rel="stylesheet">-->
	<link href="css/productlist.css" rel="stylesheet">
	<link href="css/inspiritas.css" rel="stylesheet">
	<link href="css/carousel.css" rel="stylesheet">
	<!--<why it not appears in parenttypelist.html >-->
	<script src="js/jquery-1.7.1.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
	<script src="js/jquery.json-2.4.js"></script>
    <script src="js/jquery.cookie.js"></script>
	<script src="js/jquery.form.js"></script>
	<!--<what are they>-->
	<script>
	$(document).ready(	
		function()
		{
			typeListClick();
			<?php include "htm/ready.htm";?>
			$("#cart_head").addClass('active');
			$.ajax({
				url:'index.php?act=cart.cart_show',
				type:'POST',
				success:function(data){
					//alert(data);
				}
			});
			
			
			$.getJSON('index.php?act=cart.cart_show', function(data){
			
				for(var cart in data)
				{
					html=
						'<div class="row-fluid product-row">'+
						'<div class="span1"></div>'+
						'<div id="BOOK_ID_'+data[cart].id+'" class="span1 book-item">'+
						'<div id="label'+data[cart].id+'"></div>'+
						'<a href="' + 'productDetail.php?product_id=' + data[cart].product_id + '">'+
						'<img src="'+data[cart].image+'" class="img-rounded" width="100">'+
						'</a>'+
						'</div>'+
		  
          
						'<div id="BOOK_IF_'+data[cart].id+'" class="span4">'+
						'<p>'+data[cart].name+'</p>'+
						'<p><small>'+data[cart].author+'</small></p>'+
						'<button id="DELETE_'+data[cart].id+'" class="btn" onclick="product_delete('+data[cart].id+')">删除该商品</button>'+
						'</div>'+
		  
						'<div id="BOOK_PRICE_'+data[cart].id+'"class="span3">'+
						'<p>价格:</p>'+
						'<span id="product-raw-price-content" class="book-price-saved red">￥ '+data[cart].current_price+'</span>'+
						'<tr id="saved-price-row" class="youSavePriceRow">'+
						'<td class="price-label smoke">为您节省:&nbsp;</td>'+
						'<td id="product-saved-price-content" class="book-price-saved red">'+
						'￥ '+
						'<span id="saved-value">'+data[cart].saved_value+'</span> '+
						'('+
						'<span id="saved-proportion">'+data[cart].saved_proportion+'</span>'+
						'折)'+
						'</td>'+
						'</tr>	'	+		
						'</tbody>'+
						'</div>'+
		  
						'<div id="BOOK_COUNT_'+data[cart].id+'" class="span3">'+		  
						'<div class="controls">'+
		  
						'<button id="MINUS_'+data[cart].id+'"type="minus" class="btn btn-mini" onclick="minus('+data[cart].id+')" >-</button>'+
						'<span id=COUNT_'+data[cart].id+'> '+data[cart].num+'件</span>'+
						'<button id="ADD_'+data[cart].id+'"type="add" class="btn btn-mini" onclick="add('+data[cart].id+')">+</button>'+
		 
						'</div>'+
						'</div>'+
						'</div>';
						$('#cart_list').append(html);
						var a=0;
						for(var product in data)
						{
							if(data[product].discount_type==3)
							{
							html2='<div class="absolute-label" style="top:60;width:40" >'+
								'<img id = "" style="" src="img/团购图标.png">'+
								'</div>';
							$('#label'+a).append(html2);
							}
							a++;
						}
				}
				
							
			});
			refresh_sum();
		}
	);
	
	function add(id)
	{
		$.ajax({
	   type: "POST",
	   url: 'index.php?act=cart.cart_num_add&id='+id,
	   success: function(data){
		   var countid='#COUNT_'+id;
		   //alert(data);
		   $(countid).text(data+'件');
		   refresh_sum();
	   }
	   
	 });
	}
	
	function refresh_sum()
	{
		$.ajax({
	   type: "POST",
	   url: 'index.php?act=cart.get_sum',
	   success: function(data){
			//alert(data);

			$('#sum').text('￥'+data);
	   }
	   
	 });
	}
	
	function minus(id)
	{
		$.ajax({
	   type: "POST",
	   url: 'index.php?act=cart.cart_num_minus&id='+id,
	   success: function(data){
			//alert(data);

			if(data==0)
			{
				window.location.reload();
			}
		    else
		    {
				var countid='#COUNT_'+id;
				$(countid).text(data+'件');
		    }
			refresh_sum();
	   }
	   
	 });
	}
	
	function product_delete(id)
	{
		$.ajax({
		type: "POST",
		url: 'index.php?act=cart.cart_delete&id='+id,
		success: function(data){
			//alert("删除成功");
			window.location.reload();				
			}
		});
	}
	
	function cart_empty()
	{
		$.ajax({
		type: "POST",
		url: 'index.php?act=cart.cart_empty',
		success: function(data){
			//alert("清空成功");
			window.location.reload();
			}		
		});
	}
	
	function typeListClick()
	{
		$('#type-list').children(':not(".divider,h2")').click(function(){
			$(this).addClass('active');
			$(this).siblings().removeClass('active');
		});
	}
	</script>
</head>
<body>

<?php include "htm/head.htm";?>
<div class="row-fluid product-row">
    <div class="span1 "></div>
	<div class="span10 ">
      <ul  id="cart-list" class="nav nav-list well">
		  <h2><span class="nav-header">我的购物车</span></h2>
		  
		  <section>  
			<button id="EMPTY_'+data[cart].id+'" class="btn" onclick="cart_empty('+data[cart].id+')">清空购物车</button>         
    <div class="row">    
    </div>  
</section>  

</div>
</div>

	
<div id="cart_list"></div>
	



	
<div class="row-fluid product-row hidden" >
   <div class="span1"></div>
    <div id="BOOK_ID_00001" class="span1">
          <a href="#book-detail">
            <img src="img/book-cover/jiayuan.jpg" class="img-rounded" width="100">
          </a>
		  </div>
		  
          
		  <div id="BOOK_IF_00001" class="span4">
		  <p>家你妹的园</p>
		  <p><small>哪个白痴写的</small></p>
		 <button class="btn">删死你个烧饼!</button>
		  </div>
		  
		  <div id="BOOK_PRICE_00001"class="span3">
		  <p>价格:</p>
		  <span id="product-raw-price-content" class="book-price-saved red">￥ 14.50</span>
			<tr id="saved-price-row" class="youSavePriceRow">
								<td class="price-label smoke">为您节省:&nbsp;</td>
								<td id="product-saved-price-content" class="book-price-saved red">
									￥ 
									<span id="saved-value">4.50</span> 
									(
									<span id="saved-proportion">7.6</span>
									折)
								</td>
							</tr>				
		</tbody>
		  </div>
		  
		  <div id="BOOK_COUNT_00001" class="span3">
		  <p>数量:</p>
		  
		  <div class="controls">
		  
		  <button type="minus" class="btn btn-mini" >-</button>
		  <input class="span2" type="int" id="number" >
		 <button type="add" class="btn btn-mini" >+</button>
		 
		  </div>
		</div>
</div>






	
<div id="total" class="row-fluid product-row">
<div class="span9"></div>
<div class="span3">
				<p>总计:</p>
				<p id="sum" class="book-price-new red"></p>
				<a href="admin/?act=order">
					<button class="btn btn-primary">结算</button>
				</a>

				</div>
				</div>
</div>	


<div class="row-fluid product-row">
    <div class="span12 "></div>
</div>	

<?php include "htm/footer.htm";?>
<?php include "htm/copyright.htm";?>
</body>
</html>